import {
	request
} from "@/utils/request.js";
import $utils from "@/api/serverLink.js";
import store from '../store/idnex.js';
import cryptoJs from '../utils/encryptDES.js'
let aData = Date.parse(new Date());

const sslwxbdApi = (param, c, cmd) =>
	request({
		url: $utils.sslwxbdUrl(
			"c=" + c + "&v=" + "3.0" + "&t=" + aData + "&a=" + store.state.appid
		),
		method: "POST",
		params: {
			cmd,
			base: wx.getStorageSync("baseinfo"),
			param,
		},
		c,
		type: "sslwxbdApi"
	});

const apiMixUrlApi = (param, c, cmd) =>
	request({
		url: $utils.apiMixUrl(`&a=${store.state.appid}` + "&c=" + c),
		method: "POST",
		params: {
			cmd,
			base: wx.getStorageSync("baseinfo"),
			param,
		},
		c,
		type: "apiMixUrlApi"
	});
const apiMixUrlApis = (param, c, cmd) =>
	request({
		url: $utils.apiMixUrl("&a=" + "wxze" + "&c=" + c),
		method: "POST",
		params: {
			cmd,
			base: {
				ap: "wifi",
				apiVersion: "2",
				appId: "wxze",
				deviceid: "oBgUP5UbtGi14VpPhHHJ-FV_uhJc",
				df: "devtools",
				lg: "zh_hans",
				openid: "oBgUP5UbtGi14VpPhHHJ-FV_uhJc",
				osid: "wxios",
				sha1: "385b74aeea18dce8e8b427abef5405b3",
				sid: "7f663fc693599bc5f1231f86a3577e36",
				token: "",
				ua: "iPhone XR",
				userid: "888106",
				version: "iOS 10.0.1"
			},
			param,
		},
		c,
		type: "apiMixUrlApis"
	});

const apiMixUrlKeyApi = (param, c, cmd) =>
	request({
		url: $utils.apiMixUrlKey(`&a=${store.state.appid}` + "&c=" + c),
		method: "POST",
		params: {
			cmd,
			base: wx.getStorageSync("baseinfo"),
			param,
		},
		c,
		type: "apiMixUrlKeyApi"
	});

const bsqUrl = (param, c, cmd) =>
	request({
		url: $utils.bsqUrl(
			"c=" + c + "&v=" + "3.0" + "&t=" + aData + "&a=" + store.state.appid
		),
		method: "POST",
		params: {
			cmd,
			base: wx.getStorageSync("baseinfo"),
			param,
		},
		c,
		type: "bsqUrl"
	});
// const wycUrl = (params) =>
// 	request({
// 		url: $utils.wycUrl(),
// 		method: "POST",
// 		params,
// 		type: "apiMixUrlKeyApi"
// 	});
const wycUrl = (param, c, cmd) =>
	request({
		url: $utils.wycUrl("c=" + c + "&v=" + "4" + "&a=" + store.state.appid),
		method: "POST",
		params: {
			cmd,
			base: wx.getStorageSync("baseinfo"),
			param,
		},
		c,
		type: "wycUrl"
	});
const wycUrlApi = (params) =>
	request({
		url: $utils.wycUrlApi(),
		method: "POST",
		params,
		type: "apiMixUrlKeyApi"
	});
const sslbizUrl = (param, c, cmd) =>
	request({
		url: $utils.sslbizUrl("&a=" + param.Biz_APPID + "&c=" + c),
		method: "POST",
		params: param,
		c,
		// type: "apiMixUrlKeyApi"
	});
store.state.appid
const drawUrl = (param, c, cmd) =>
	request({
		url: $utils.drawUrl("c=" + c + "&v=" + "1" + "&a=" + store.state.appid),
		// url: $utils.drawUrl("c=" + c + "&v=" + "1" + "&a=" + appId),
		method: "POST",
		params: {
			cmd,
			base: wx.getStorageSync("baseinfo"),
			param,
		},
		c,
		type: "drawUrl"
	});
	//流式写作接口
const black = (param) =>

	wx.request({
		url: 'https://biz.teltranslator.com/chat/api/c=1012&v=4&a=wxzy', // 服务端接口地址
		data: cryptoJs.encrypt(JSON.stringify({
			cmd: "bdStream",
			base: wx.getStorageSync("baseinfo"),
			param,
		}),1012),
		method: 'POST',
		enableChunked: true,
		header: {
			//'content-type': 'application/x-www-form-urlencoded',
			Accept: 'text/event-stream'
		},
		success: (response) => {
			// 开启enableChunked后，成功的回调一般用不到，因为响应数据不在这里返回
			// console.log(response, '成功结束',getApp().globalData.Liupaer);
			if(response.errMsg == "request:ok"){
				// getApp().globalData.Liupaer = true
				// console.log(getApp().globalData.Liupaer)
			}
		},
		fail: (err) => {
			// 开启enableChunked后，成功的回调一般用不到，因为响应数据不在这里返回
			console.log(err, '失败');
		}
	});
export {
	sslwxbdApi,
	apiMixUrlApi,
	apiMixUrlKeyApi,
	bsqUrl,
	wycUrl,
	wycUrlApi,
	sslbizUrl,
	drawUrl,
	apiMixUrlApis,
	black
	// sslbizUrlApi
};